package com.googlecode.moneyManager.dao.hib;

import com.googlecode.moneyManager.dao.CurrencyExchangeEventDAO;
import com.googlecode.moneyManager.exceptions.DataAccessException;
import com.googlecode.moneyManager.model.CurrencyExchangeEvent;
import com.googlecode.moneyManager.model.Customer;
import com.googlecode.moneyManager.model.SecurityValue;
import org.hibernate.Criteria;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Restrictions;
import org.joda.time.DateTime;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.List;

/**
 * Created by sergiy.doroshenko
 * Date: 5/20/11
 */
public class CurrencyExchangeEventDAOHib  extends HibernateDaoSupport implements CurrencyExchangeEventDAO{
    @Override
    public String create(CurrencyExchangeEvent currencyExchangeEvent) throws DataAccessException {
        throw  new UnsupportedOperationException();
    }

    @Override
    public void saveOrUpdate(CurrencyExchangeEvent currencyExchangeEvent) throws DataAccessException {
           getHibernateTemplate().saveOrUpdate(currencyExchangeEvent);
    }

    @Override
    public void merge(CurrencyExchangeEvent currencyExchangeEvent) throws DataAccessException {
           throw  new UnsupportedOperationException();
    }

    @Override
    public void delete(CurrencyExchangeEvent currencyExchangeEvent) throws DataAccessException {
           throw  new UnsupportedOperationException();
    }

    @Override
    public CurrencyExchangeEvent get(String id) throws DataAccessException {
        throw  new UnsupportedOperationException();
    }

    @Override
    public List<CurrencyExchangeEvent> getAll() throws DataAccessException {
        throw  new UnsupportedOperationException();
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<CurrencyExchangeEvent> find(DateTime dateTime) {
        DetachedCriteria criteria = DetachedCriteria.forClass(CurrencyExchangeEvent.class);
        criteria.add(Restrictions.between("date", dateTime.toDateMidnight().toDate(),
                dateTime.plusDays(1).toDateMidnight().toDate()));
        return getHibernateTemplate().findByCriteria(criteria);
    }
}
